<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/16
 * Time: 10:07
 */
//引用DbTools.php和common.php
include_once '../tools/DbTools.php';
include_once '../tools/common.php';
//开启SESSION
session_start();
//使用getLoginStatus方法
$is_login = getLoginStatus();
//通过getLoginStatus方法判断登录状态
if(!$is_login){
    echo '尚未登陆，<a href="../user/loginUi.php">请先登录</a>';
    die;
}else {
    //通过SESSION获取到COOKIE中的数据
    $userinfo = $_SESSION[$_COOKIE['Token']];
    //初始化数据库
    DbTools::InitDb();
    //使用MYSQL语句用于查询
    //查询出除主卡以外该用户所拥有的其它银行卡卡号和状态
    $sql = "select * from bankcard where CardState = 0 and AccountId = " . $userinfo['AccountId'] . ' and CardId != ' . $userinfo['CardId'];
    //执行select方法用于完成查询
    $result = DbTools::select($sql);
    //关闭数据库连接
    DbTools::close();
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
<form action="removeAnotherCards.php" method="post">
    <table border="1" cellspacing="0" cellpadding="10px">
        <tr>
            <th><input type="checkbox" onclick="checkAll(event)" /></th>
            <th>序号</th>
            <th>卡号</th>
            <th>余额</th>
        </tr>
        <!--遍历数组，并用$item代替$result，$key用于表示序号($key+1表示从1开始)-->
        <?php foreach($result as $key => $item){?>
        <tr>
            <td><input type="checkbox" name="cardCheck[]" value="" /></td>
            <td><?php echo $key+1;?></td>
            <td><?php echo $item['CardNo']?></td>
            <td><?php echo $item['CardMoney']?></td>
        <?php }?>
        </tr>
    </table>
    <button type="submit">注销银行卡</button>&nbsp;&nbsp;<a href="../user/userinfo.php">返回用户中心</a>
</form>
</body>
<script type="text/javascript">
    function checkAll(event){
        //js完成checkBox全选
        var checkStatus = event.target.checked;
        var cards = document.getElementsByName('cardCheck[]');
        for(var i = 0 ; i<cards.length ; i++){
            cards[i].checked = checkStatus();
        }
    }
</script>
</html>
